"""
@name : 3-5.线程锁-条件锁-2
@author : wenyao
@projectname: sanchuanglianxi
"""
#wait_for ：等待函数返回结果，True一次放行一个线程
import threading

#print(threading.enumerate())

lock = threading.Condition()

def condition():
    ret = False
    inp = input(">>>")
    if inp == "yes":
        ret = True
    return ret

def task(i):
    #with lock:
        lock.acquire()
        print(f"start condition {i}")
        lock.wait_for(condition)
        print(f"run the thread {i}")
        lock.release()

for i in range(10):
    t = threading.Thread(target=task, args = (i,))
    t.start()

#print(threading.enumerate())
#
# def condition():
#     ret = False
#     inp = input(">>>")
#     if inp == "yes":
#         ret = True
#     return ret